package com.gagakuai.bpm.dao.mapper.scheduleTask;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gagakuai.bpm.domian.dto.scheduleTask.BPMUserVo;
import com.gagakuai.bpm.domian.dto.scheduleTask.Group;
import com.gagakuai.bpm.domian.dto.scheduleTask.User;
import com.gagakuai.bpm.domian.dto.scheduleTask.UserOfGroup;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserInfoMapper extends BaseMapper<BPMUserVo> {

//    @Insert("<script>"
//            +" insert into ACT_ID_GROUP(ID_, NAME_, TYPE_)"
//            + "  values "
//            + " <foreach collection = 'groupList' item = 'item' separator = '),(' open = '(' close = ')' >"
//            + " #{item.deptId}, #{item.name}, '_USER' "
//            + "  </foreach> "
//            +"</script>")
    @Update(" <script> " +
            " <foreach collection = 'groupList' item = 'item' separator = ';' > " +
            "  insert into ACT_ID_GROUP (ID_, NAME_) values   " +
            "  ( #{item.deptId}, #{item.name} ) " +
            " ON DUPLICATE KEY UPDATE NAME_ = #{item.name} " +
            " </foreach>  " +
            " </script> ")
    int batchGroup(@Param("groupList") List<Group> groupList);

//    @Insert("<script>"
//            +" insert into ACT_ID_USER(ID_, FIRST_)"
//            + "  values "
//            + " <foreach collection = 'userList' item = 'item' separator = '),(' open = '(' close = ')' >"
//            + " #{item.id}, #{item.name} "
//            + "  </foreach> "
//            +"</script>")
    @Update(" <script> " +
            " <foreach collection = 'userList' item = 'item' separator = ';' > " +
            "  insert into ACT_ID_USER(ID_, FIRST_) values   " +
            "  ( #{item.id}, #{item.name} ) " +
            " ON DUPLICATE KEY UPDATE FIRST_ = #{item.name} " +
            " </foreach>  " +
            " </script> ")
    int batchUser(@Param("userList")List<User> userList);

    @Insert("<script>"
            +" insert into ACT_ID_MEMBERSHIP(USER_ID_, GROUP_ID_)"
            + "  values "
            + " <foreach collection = 'userOfGroupList' item = 'item' separator = '),(' open = '(' close = ')' >"
            + " #{item.userId}, #{item.groupId} "
            + "  </foreach> "
            +"</script>")
    int batchUserOfGroup(@Param("userOfGroupList")List<UserOfGroup> userOfGroupList);

    @Update(" delete from ACT_ID_GROUP where  TYPE_ != 'SYSTEM' ")
    void deleteGroup();

    @Update(" delete from ACT_ID_USER where ID_ !='demo' and FIRST_ !='Demo' ")
    void deleteUser();

    @Update(" delete from ACT_ID_MEMBERSHIP  where USER_ID_ != 'demo' and  GROUP_ID_ != 'camunda-admin' ")
    void deleteUserOfGroup();
}
